<template>
  <div class="Statisticsadmin">
    <div class="Statisticsadmin-one">
      <div>
        <div>{{ detail.allocation_number }}</div>
        <div :style="{
          background:
            detail.status == 0
              ? '#E6A23C'
              : detail.status == 1
                ? '#67C23A'
                : detail.status == 2
                  ? '#F56C6C'
                  : detail.status == 3
                    ? '#909399'
                    : '',
        }">
          {{ detail.status | statusTitle }}
        </div>
        <div :style="{
          color:
            detail.data_return == 1
              ? '#E6A23C'
              : detail.data_return == 2
                ? '#67C23A'
                : '',
          borderColor:
            detail.data_return == 1
              ? '#E6A23C'
              : detail.data_return == 2
                ? '#67C23A'
                : '#333333',
        }">
          {{ detail.data_return | is_returnTitle }}
        </div>
      </div>
      <div>
        <div>
          <span style="color: #2c70d6">借出</span>
          /
          <span :style="{
            color:
              detail.data_status == 0
                ? '#67C23A'
                : detail.data_status == 1
                  ? '#F56C6C'
                  : '',
          }">
            {{ detail.data_status | datastatusTitle }}</span>
        </div>
        <div>
          计划借出数量/实际借出数量：：<span style="font-weight: 600">{{
            detail.jh_jc_num
          }}</span>/<span style="font-weight: 600; color: red">{{
  detail.sj_jc_num || 0
}}</span>
        </div>
        <div>申请事由：{{ detail.reason || "-" }}</div>
      </div>
      <div>
        <div>
          <div>邮</div>
          <div>
            运输方式：{{ detail.transport_type || "-" }}
            <span style="margin-left: 10px" v-if="detail.courier_number">快递单号：{{ detail.courier_number }}</span>
          </div>
        </div>
        <div>
          <span>{{
            detail.wp_province +
            detail.wp_city +
            detail.wp_area +
            detail.wp_address
          }}</span>
          <span>
            {{ detail.wp_user }}
          </span>
          <span>
            {{ detail.wp_phone }}
          </span>
        </div>
        <div>
          <div>备</div>
          <div>{{ detail.remark || "-" }}</div>
        </div>
      </div>
    </div>
    <div class="Statisticsadmin-two">
      <div class="line Statisticsadmin-two-title">借出列表</div>
      <div style="margin: 10px 0">
        <!-- <el-button
          :disabled="!multipleSelection.length"
          type="primary"
          size="mini"
          @click="dialogVisible = true"
          >归还所选</el-button
        >
        <el-button
          type="primary"
          size="mini"
          :disabled="detail.data_return == 1"
          >未归还转内购</el-button
        > -->
        <el-button type="primary" size="mini" @click="onNGModel"
          v-if="detail.data_status == 0 && detail.data_return != 2 && detail.status != 2 && detail.status != 3">未归还转内购</el-button>
        <el-button type="warning" size="mini" @click="postAdminOmssetAllocationtcclose"
          v-if="detail.data_status == 0 && detail.data_return != 2">关闭借出计划</el-button>
      </div>
      <el-table :data="list" border style="width: 100%" size="mini">
        <el-table-column prop="type_name" label="商品信息" width="400">
          <template slot-scope="{ row }">
            <div class="goodsInfo">
              <el-image :src="row.img" fit="contain" :lazy="true"></el-image>
              <div>
                <div>{{ row.type_name }}</div>
                <div>{{ row.sku_code }}</div>
                <div>{{ row.type_no }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="jh_jc_num" label="计划借出/实际借出数量">
          <template slot-scope="{ row }">
            <div style="font-size: 18px">
              <span>{{ row.jh_jc_num || 0 }}</span> /
              <span style="color: red"> {{ row.sj_jc_num || 0 }} </span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="sj_gh_num" label="已归还数量">
          <template slot-scope="{ row }">
            <div style="font-size: 18px">{{ row.sj_gh_num }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="zng_num" label="已转内购数">
          <template slot-scope="{ row }">
            <div>{{ row.zng_num || 0 }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="jzs_num" label="已转赠送数">
          <template slot-scope="{ row }">
            <div>{{ row.jzs_num || 0 }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="is_return" label="归还状态">
          <template slot-scope="{ row }">
            <div :style="{
              color:
                row.is_return == 1
                  ? '#E6A23C'
                  : row.is_return == 2
                    ? '#67C23A'
                    : '',
            }">
              {{
                row.is_return == 0
                ? "未归还"
                : row.is_return == 1
                  ? "部分归还"
                  : row.is_return == 2
                    ? "全部归还"
                    : ""
              }}
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="address" label="未归还件状态"> </el-table-column> -->
      </el-table>
    </div>
    <div class="Statisticsadmin-two">
      <div class="line Statisticsadmin-two-title">归还列表</div>
      <div style="margin: 10px 0">
        <el-radio-group v-model="radio" size="mini" @input="onInputRadio">
          <el-radio-button label="归还"></el-radio-button>
          <el-radio-button label="转内购"></el-radio-button>
          <el-radio-button label="转赠送"></el-radio-button>
        </el-radio-group>
      </div>
      <div v-if="radio == '归还'">
        <el-form ref="form" :model="form" label-position="top" class="myform" size="mini">
          <div>
            <el-form-item label="归还单号" class="myform-item">
              <el-input v-model="form.number" placeholder="请输入归还单号" @keyup.enter.native="onSearch" clearable></el-input>
            </el-form-item>
            <el-form-item label="归还审批状态" class="myform-item">
              <el-select v-model="form.status" placeholder="请选择" clearable>
                <el-option v-for="item in optionsSP" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="归还发起时间" class="myform-item">
              <el-date-picker v-model="form.str_time" type="daterange" range-separator="至" start-placeholder="开始日期"
                end-placeholder="结束日期" value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
            <el-form-item style="margin-top: 38px">
              <el-button type="primary" @click="onSearch">查询</el-button>
            </el-form-item>
          </div>
          <div></div>
        </el-form>
        <el-table :data="tableData" border style="width: 100%" size="mini">
          <el-table-column prop="allocation_number" label="归还单号">
          </el-table-column>
          <el-table-column prop="type_name" label="商品信息" width="400">
            <template slot-scope="{ row }">
              <div class="goodsInfo">
                <el-image :src="row.img" fit="contain" :lazy="true"></el-image>
                <div>
                  <div>{{ row.type_name }}</div>
                  <div>{{ row.sku_code }}</div>
                  <div>{{ row.type_no }}</div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="num" label="计划归还数量"> </el-table-column>
          <el-table-column prop="createtime" label="归还发起时间">
          </el-table-column>
          <el-table-column prop="status" label="归还审核状态">
            <template slot-scope="{ row }">
              <div :style="{
                color:
                  row.status == 0
                    ? '#E6A23C'
                    : row.status == 1
                      ? '#67C23A'
                      : row.status == 2
                        ? '#F56C6C'
                        : row.status == 3
                          ? '#909399'
                          : '',
              }">
                {{
                  row.status == 0
                  ? "审核中"
                  : row.status == 1
                    ? "已通过"
                    : row.status == 2
                      ? "已拒绝"
                      : row.status == 3
                        ? "已撤销"
                        : ""
                }}
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div v-if="radio == '转内购'">
        <el-form ref="form" :model="form" label-position="top" class="myform" size="mini">
          <div>
            <el-form-item label="单号" class="myform-item">
              <el-input v-model="form.number" placeholder="单号" @keyup.enter.native="onSearch" clearable></el-input>
            </el-form-item>
            <el-form-item label="审批状态" class="myform-item">
              <el-select v-model="form.status" placeholder="请选择" clearable>
                <el-option v-for="item in optionsSP" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="发起时间" class="myform-item">
              <el-date-picker v-model="form.str_time" type="daterange" range-separator="至" start-placeholder="开始日期"
                end-placeholder="结束日期" value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
            <el-form-item style="margin-top: 38px">
              <el-button type="primary" @click="onSearch">查询</el-button>
            </el-form-item>
          </div>
          <div></div>
        </el-form>
        <el-table :data="tableData" border style="width: 100%" size="mini">
          <el-table-column prop="allocation_number" label="单号">
          </el-table-column>
          <el-table-column prop="type_name" label="商品信息" width="400">
            <template slot-scope="{ row }">
              <div class="goodsInfo">
                <el-image :src="row.img" fit="contain" :lazy="true"></el-image>
                <div>
                  <div>{{ row.type_name }}</div>
                  <div>{{ row.sku_code }}</div>
                  <div>{{ row.type_no }}</div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="num" label="转内购数"> </el-table-column>
          <el-table-column prop="createtime" label="发起时间">
          </el-table-column>
          <el-table-column prop="status" label="审核状态">
            <template slot-scope="{ row }">
              <div :style="{
                color:
                  row.status == 0
                    ? '#E6A23C'
                    : row.status == 1
                      ? '#67C23A'
                      : row.status == 2
                        ? '#F56C6C'
                        : row.status == 3
                          ? '#909399'
                          : '',
              }">
                {{
                  row.status == 0
                  ? "审核中"
                  : row.status == 1
                    ? "已通过"
                    : row.status == 2
                      ? "已拒绝"
                      : row.status == 3
                        ? "已撤销"
                        : ""
                }}
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div v-if="radio == '转赠送'">
        <el-form ref="form" :model="form" label-position="top" class="myform" size="mini">
          <div>
            <el-form-item label="单号" class="myform-item">
              <el-input v-model="form.number" placeholder="单号" @keyup.enter.native="onSearch" clearable></el-input>
            </el-form-item>
            <el-form-item label="审批状态" class="myform-item">
              <el-select v-model="form.status" placeholder="请选择" clearable>
                <el-option v-for="item in optionsSP" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="发起时间" class="myform-item">
              <el-date-picker v-model="form.str_time" type="daterange" range-separator="至" start-placeholder="开始日期"
                end-placeholder="结束日期" value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
            <el-form-item style="margin-top: 38px">
              <el-button type="primary" @click="onSearch">查询</el-button>
            </el-form-item>
          </div>
          <div></div>
        </el-form>
        <el-table :data="tableData" border style="width: 100%" size="mini">
          <el-table-column prop="allocation_number" label="单号">
          </el-table-column>
          <el-table-column prop="type_name" label="商品信息" width="400">
            <template slot-scope="{ row }">
              <div class="goodsInfo">
                <el-image :src="row.img" fit="contain" :lazy="true"></el-image>
                <div>
                  <div>{{ row.type_name }}</div>
                  <div>{{ row.sku_code }}</div>
                  <div>{{ row.type_no }}</div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="num" label="转赠送数"> </el-table-column>
          <el-table-column prop="createtime" label="发起时间">
          </el-table-column>
          <el-table-column prop="status" label="审核状态">
            <template slot-scope="{ row }">
              <div :style="{
                color:
                  row.status == 0
                    ? '#E6A23C'
                    : row.status == 1
                      ? '#67C23A'
                      : row.status == 2
                        ? '#F56C6C'
                        : row.status == 3
                          ? '#909399'
                          : '',
              }">
                {{
                  row.status == 0
                  ? "审核中"
                  : row.status == 1
                    ? "已通过"
                    : row.status == 2
                      ? "已拒绝"
                      : row.status == 3
                        ? "已撤销"
                        : ""
                }}
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <el-dialog title="归还确认" :visible.sync="dialogVisible" width="1600px">
      <div>
        <div>
          <div class="line" style="font-weight: 600; margin-bottom: 10px">
            已选信息
          </div>
          <el-table :data="multipleSelection" border style="width: 100%" size="mini">
            <el-table-column prop="type_name" label="商品信息" width="400">
              <template slot-scope="{ row }">
                <div class="goodsInfo">
                  <el-image :src="row.img" fit="contain" :lazy="true"></el-image>
                  <div>
                    <div>{{ row.type_name }}</div>
                    <div>{{ row.sku_code }}</div>
                    <div>{{ row.type_no }}</div>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="jh_jc_num" label="计划借出/实际借出数量">
              <template slot-scope="{ row }">
                {{ row.jh_jc_num || 0 }} / {{ row.sj_jc_num || 0 }}
              </template>
            </el-table-column>
            <el-table-column prop="sj_gh_num" label="已归还数量">
            </el-table-column>
            <el-table-column prop="zng_num" label="已转内购数">
              <template slot-scope="{ row }">
                <div>{{ row.zng_num || 0 }}</div>
              </template>
            </el-table-column>
            <el-table-column prop="num" label="计划归还数量">
              <template scope="{ row }">
                <el-input v-model="row.num" placeholder="请输入计划归还数量" size="mini" type="number" clearable></el-input>
              </template>
            </el-table-column>
          </el-table>
          <!-- <div>统计：计划归还共<span>15</span>件</div> -->
        </div>
        <div>
          <div class="line" style="font-weight: 600; margin: 10px 0">
            邮寄信息
          </div>
          <div class="content">
            <div class="content-one">
              <div>
                <div class="star" style="margin-bottom: 10px">快递单号:</div>
                <el-input v-model="formGh.ourier_number" placeholder="请输入快递单号" size="mini" clearable></el-input>
              </div>
              <div>
                <div class="star" style="margin-bottom: 10px">运输方式:</div>
                <el-select v-model="formGh.logistics_company_code" placeholder="请选择" size="mini" @change="handleChange">
                  <el-option v-for="item in Courier" :key="item.logistics_company_name"
                    :label="item.logistics_company_name" :value="item.logistics_company_code">
                  </el-option>
                </el-select>
              </div>
            </div>
            <div class="content-two">
              <div>
                <div class="star">联系人</div>
                <el-input readonly v-model="formGh.wp_user" placeholder="请输入联系人" size="mini" clearable></el-input>
              </div>
              <div>
                <div class="star">联系电话</div>
                <el-input readonly v-model="formGh.wp_phone" placeholder="请输入联系电话" size="mini" clearable></el-input>
              </div>
              <div>
                <div class="star">邮寄地址</div>
                <div>
                  <el-input style="width: 400px" readonly v-model="formGh.wp_address" placeholder="请输入邮寄地址" size="mini"
                    clearable></el-input>
                </div>
              </div>
            </div>
            <div>
              <div class="" style="margin-bottom: 10px">备注</div>
              <el-input type="textarea" v-model="formGh.remark" placeholder="请输入备注" size="mini" clearable></el-input>
            </div>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" :loading="loading" :disabled="!formGh.ourier_number || !formGh.transport_type"
          @click="onSubmit">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="商品转内购" :visible.sync="dialogVisibleZNG" width="1200px">
      <div v-if="step == 1">
        <div class="line" style="font-weight: 600; margin-bottom: 10px">
          商品金额信息
        </div>
        <div class="zk">
          <div class="star">商品折扣</div>
          <el-input v-model="zk" placeholder="请输入折扣" type="number" size="mini"></el-input>
        </div>
        <el-table size="mini" :data="TableDataNG" height="400" style="width: 100%"
          @selection-change="handleSelectionChange" border>
          <el-table-column type="selection" align="center" width="55">
          </el-table-column>
          <el-table-column prop="img" label="图片" width="80">
            <template slot-scope="{ row }">
              <el-image v-if="row.img" style="width: 50px; height: 50px" :src="row.img" fit="contain"
                :preview-src-list="[row.img]"></el-image>
            </template>
          </el-table-column>
          <el-table-column prop="type_name" label="款名"> </el-table-column>
          <el-table-column prop="sku_code" label="SKU" width="160">
          </el-table-column>
          <el-table-column prop="ngnum" label="可转内购数" width="120">
          </el-table-column>
          <el-table-column prop="selling_price" label="单价" width="160">
            <template slot-scope="{ row, $index }">
              <el-input style="width: 120px" type="number" v-model="row.selling_price" placeholder="请输入单价" size="mini"
                @input="onInputSelling_price($event, $index)"></el-input>
            </template>
          </el-table-column>
          <!-- <el-table-column label="折扣" width="80">
            <template> 0.68 </template>
          </el-table-column> -->
          <el-table-column prop="num" label="转内购数" width="140">
            <template slot-scope="{ row, $index }">
              <el-input type="number" v-model="row.num" placeholder="请输入转内购数" size="mini"
                @input="onInput($event, $index)"></el-input>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="zh_price" label="折后金额" width="140">
          </el-table-column> -->
        </el-table>
        <!-- <div>统计：计划归还共<span>15</span>件</div> -->
      </div>
      <div class="Transfers" v-if="step == 2">
        <div class="Transfers-type">
          <div>
            <div>重要提示：</div>
            <div>内购打款请汇入正确银行账户，具体信息见下方备注！</div>
          </div>
          <div>
            <div>注：</div>
            <div>
              <div>1、试用期员工转正后享受内购福利；</div>
              <div>2、正式员工享受每月一套的福利，发货优先客户订单；</div>
              <div>3、内购可换尺码，不可退；</div>
              <div v-if="is_subject == 'kz'">
                4、十三余收款为 <span>户名：年年有余 (浙江)文化科技有限公司</span>
                <span>开户行：杭州联合银行九堡支行</span>
                <span>账号：201000242198455</span>
              </div>
              <div v-if="is_subject == 'mz'">
                4、妙哉收款为 <span>户名：杭州妙哉文化有限公司</span>
                <span>开户行：上海浦东发展银行杭州分行营业部</span>
                <span>账号：95200078801000002375</span>
              </div>
            </div>
          </div>
        </div>
        <div class="line" style="font-weight: 600; margin-bottom: 10px">
          商品金额信息
        </div>
        <el-table size="mini" :data="Summary" style="width: 100%" border>
          <el-table-column prop="num" label="数量汇总" align="center">
          </el-table-column>
          <el-table-column prop="selling_price" label="原价金额汇总" align="center">
          </el-table-column>
          <el-table-column label="折扣" align="center">
            <template> {{ zk }} </template>
          </el-table-column>
          <el-table-column prop="zh_price" label="折后金额汇总" align="center">
          </el-table-column>
        </el-table>
        <div class="info">
          <div>
            <div class="star">付款信息（ 只允许上传一张图片 ）</div>
            <div>
              <el-upload action="https://ssy.13yu.com/index.php/Admin/Api/upload" :on-success="handleAvatarSuccess"
                :show-file-list="false" v-if="!images.length">
                <i class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
              <div v-else>
                <div class="fileimg" @mouseenter="mouse = 1" @mouseleave="mouse = 0">
                  <el-image :src="images[0].url" fit="contain" class="fileimg-image"></el-image>
                  <div class="fileimg-operation" v-if="mouse == 1">
                    <div @click="handlePictureCardPreview(images[0])">
                      <i class="el-icon-zoom-in pointer"></i>
                    </div>
                    <div @click="handleRemovesXJ(images[0])">
                      <i class="el-icon-delete pointer"></i>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="onLeft">{{
          step == 1 ? "取消" : "上一步"
        }}</el-button>
        <el-button type="primary" :loading="loading" @click="onSubmitNGNext" v-if="step == 1">下一步</el-button>
        <el-button type="primary" :loading="loading" @click="onSubmitNG" v-else :disabled="!images.length">提 交</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="dialogVisibleImage" :modal="false">
      <img width="100%" :src="dialogImageUrl" alt="" />
    </el-dialog>
  </div>
</template>

<script>
import pagination from "@/components/pagination.vue";
import { floatMultiply, floatAdd, floatDivide } from "@/utils/algorithm.js";
import {
  postAdminOmsgetAllocationtdetail,
  postAdminOmsgetlogisticsCompanyCode,
  postAdminOmsSetAllocation,
  postAdminOmsgetWarehouseaddress,
  postAdminOmssetAllocationtcclose,
  postAdminOmsgetWarehousereturn,
  postAdminOmsGetsAllocation_ipurchase,
  postAdminOmsGetsAllocation_ipurchaseuserinfo,
  postAdminOmsSetAllocation_ipurchase,
  postAdminOmsGetWarehouseTransfer,
  postAdminOmsGetWarehouseGive
} from "@/api";
import { getStore } from "@/utils/localStorage.js";
import { regionData } from "element-china-area-data";
export default {
  components: { pagination },
  filters: {
    groupsTitle(e) {
      if (e == 1) return "赠送";
      if (e == 2) return "借出";
      if (e == 3) return "归还";
      return e;
    },
    statusTitle(e) {
      if (e == 0) return "审核中";
      if (e == 1) return "已通过";
      if (e == 2) return "已拒绝";
      if (e == 3) return "已撤销";
      return e;
    },
    is_returnTitle(e) {
      if (e == 0) return "未归还";
      if (e == 1) return "部分归还";
      if (e == 2) return "全部归还";
      return e;
    },
    datastatusTitle(e) {
      if (e == 0) return "正常";
      if (e == 1) return "关闭";
      return e;
    },
  },
  data() {
    return {
      loading: false,
      dialogVisible: false,
      dialogVisibleZNG: false,
      dialogVisibleImage: false,
      dialogImageUrl: "",
      address: regionData,
      radio: "归还",
      TableDataNG: [],
      mouse: 0,
      zk: 6.8,
      step: 1,
      form: {
        allocation_number: "",
        number: "",
        str_time: "",
        end_time: "",
        status: "",
      },
      optionsSP: [
        {
          value: "0",
          label: "审核中",
        },
        {
          value: "1",
          label: "已通过",
        },
        {
          value: "2",
          label: "已拒绝",
        },
        {
          value: "3",
          label: "已撤销",
        },
      ],
      detail: "",
      list: [],
      images: [],
      multipleSelection: [],
      tableData: [],
      total: 0,
      Courier: [],
      formGh: {
        groups: 3,
        transport_type: "",
        allocation_number: "",
        logistics_company_code: "",
        wp_user: "",
        wp_phone: "",
        wp_province: "",
        wp_city: "",
        wp_area: "",
        wp_address: "",
        remark: "",
        reason: "归还所借商品",
        ourier_number: "",
        multipleSelection: [],
      },
      Summary: [
        {
          num: 0,
          selling_price: 0,
          zh_price: 0,
        },
      ],
      is_subject: "kz"
    };
  },
  activated() {
    this.is_subject = getStore("userinfo").is_subject;
    this.start();
  },
  methods: {
    // 关闭
    async postAdminOmssetAllocationtcclose() {
      let { detail } = this;
      let obj = {
        allocation_number: detail.allocation_number,
      };
      this.$confirm("确定关闭借出计划?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          await postAdminOmssetAllocationtcclose(obj);
          this.postAdminOmsgetAllocationtdetail(obj);
        })
        .catch(() => { });
    },
    onInputRadio(e) {
      console.log("e------>", e);
      this.form = {
        allocation_number: this.$route.query.allocation_number,
        number: "",
        str_time: "",
        end_time: "",
        status: "",
      };
      if (e == "转内购") {
        this.postAdminOmsGetWarehouseTransfer(this.form);
      } else if (e == "转赠送") {
        this.postAdminOmsGetWarehouseGive(this.form)
      } else {
        this.postAdminOmsgetWarehousereturn(this.form);
      }

    },
    // 转内购列表
    async postAdminOmsGetWarehouseTransfer(data) {
      this.form = data;
      let form = JSON.parse(JSON.stringify(this.form));
      if (form.str_time) {
        form.str_time = `${data.str_time[0]}`;
        form.end_time = `${data.str_time[1]}`;
      } else {
        form.str_time = "";
        form.end_time = "";
      }
      let res = await postAdminOmsGetWarehouseTransfer(form);
      this.tableData = res.data;
    },
    start() {
      let radio = this.radio;
      let allocation_number = this.$route.query.allocation_number;
      let data = {
        allocation_number,
      };
      this.formGh.allocation_number = allocation_number;
      this.form.allocation_number = allocation_number;
      this.postAdminOmsgetAllocationtdetail(data);
      this.postAdminOmsgetlogisticsCompanyCode();
      this.postAdminOmsgetWarehouseaddress();
      if (radio == "转内购") {
        this.postAdminOmsGetWarehouseTransfer(this.form);
      } else if (radio == "转赠送") {
        this.postAdminOmsGetWarehouseGive(this.form)
      } else {
        this.postAdminOmsgetWarehousereturn(this.form);
      }
    },
    async onSubmitNG() {
      this.loading = true;
      let allocation_number = this.$route.query.allocation_number;
      let addressobj = {
        allocation_number: allocation_number,
      };
      let resaddress = await postAdminOmsGetsAllocation_ipurchaseuserinfo(
        addressobj
      );
      let addressData = resaddress.data;
      let { multipleSelection, images, zk } = this;
      zk = floatDivide(zk, 10);
      let arr = [];
      for (let index = 0; index < multipleSelection.length; index++) {
        let obj = {
          sku_code: multipleSelection[index].sku_code,
          num: multipleSelection[index].num,
          selling_price: multipleSelection[index].selling_price,
        };
        arr.push(obj);
      }
      let obj = {
        wp_user: addressData.wp_user,
        wp_phone: addressData.wp_phone,
        wp_province: addressData.wp_province,
        wp_city: addressData.wp_city,
        wp_area: addressData.wp_area,
        wp_address: addressData.wp_address,
        images,
        arrlist: arr,
        allocation_number,
        types: 1,
        discount: zk,
      };
      try {
        let res = await postAdminOmsSetAllocation_ipurchase(obj);
        this.$message.success("提交成功");

        this.loading = false;
        this.number = "";
        this.wp_phone = "";
        this.wp_address = "";
        this.wp_user = "";
        this.wp_province = "";
        this.wp_city = "";
        this.wp_area = "";
        this.Couriertype = "";
        this.tableData = [];
        this.multipleSelection = [];
        this.TableDataSelect = [];
        this.selectedOptions = [];
        this.multipleSelection = [];
        this.zk = 6.8;
        this.step = 1;
        this.Summary = {
          num: 0,
          selling_price: 0,
          zh_price: 0,
        };
        this.images = [];
        this.dialogVisibleZNG = false;
        this.start();
      } catch (error) {
        this.loading = false;
      }
    },
    handleAvatarSuccess(res, file) {
      console.log("res", res);
      console.log("file", file);
      if (res.code == 0) {
        let obj = {
          name: "图片",
          url: res.img,
        };
        this.images = [obj];
      }
    },
    onLeft() {
      let { step } = this;
      if (step == 1) {
        this.multipleSelection = [];
        this.dialogVisibleZNG = false;
      } else {
        this.step = 1;
      }
    },
    TableDataSelectSummary() {
      let { multipleSelection, zk } = this;
      zk = floatDivide(zk, 10);
      let Summary = {
        num: 0,
        selling_price: 0,
        zh_price: 0,
      };
      multipleSelection.forEach((e) => {
        if (e.num) {
          Summary.num = floatAdd(Summary.num, e.num);
        }
        if (e.selling_price) {
          Summary.selling_price = floatAdd(
            Summary.selling_price,
            floatMultiply(e.selling_price, e.num)
          );
        }
        // if (e.zh_price) {
        //   Summary.zh_price = floatAdd(
        //     Summary.zh_price,
        //     e.zh_price
        //   );
        // }
      });
      Summary.zh_price = floatMultiply(Summary.selling_price, zk);
      this.Summary = [Summary];
    },
    onSubmitNGNext() {
      let { multipleSelection, zk } = this;
      if (zk >= 0) {
        if (multipleSelection.length) {
          let is = multipleSelection.some((e) => {
            return (
              !e.num ||
              !e.selling_price ||
              e.selling_price < 0 ||
              !e.num < 0 ||
              e.num > e.ngnum
            );
          });
          if (is) {
            this.$message.warning("选中商品的数量和单价不能为空且必须大于0！");
          } else {
            this.TableDataSelectSummary();
            this.step = 2;
          }
        } else {
          this.$message.warning("请勾选需要转内购的商品！");
        }
      } else {
        this.$message.warning("商品折扣不能为空且不能小于0");
      }
    },
    handleRemovesXJ(file) {
      let { images } = this;
      let index = images.findIndex((e) => e.url == file.url);
      images.splice(index, 1);
      this.images = images;
      return true;
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisibleImage = true;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    onInput(e, index) {
      // let { TableDataNG, multipleSelection } = this;
      // let tmpObj = TableDataNG[index];
      // if (Number(e)) {
      //   tmpObj.num = e;
      //   if (tmpObj.selling_price) {
      //     tmpObj.zh_price = floatMultiply(
      //       floatMultiply(Number(tmpObj.selling_price), 0.68),
      //       e
      //     );
      //   } else {
      //     tmpObj.zh_price = 0;
      //   }
      // } else {
      //   tmpObj.num = 1;
      //   if (tmpObj.selling_price) {
      //     tmpObj.zh_price = floatMultiply(Number(tmpObj.selling_price), 0.68);
      //   } else {
      //     tmpObj.zh_price = 0;
      //   }
      // }
      // this.$set(this.TableDataNG, index, tmpObj);
      // this.multipleSelection = multipleSelection.map((e) => {
      //   if (e.id == tmpObj.id) return tmpObj;
      //   return e;
      // });
    },
    onInputSelling_price(e, index) {
      // let { TableDataNG, multipleSelection } = this;
      // let tmpObj = TableDataNG[index];
      // if (Number(e)) {
      //   tmpObj.selling_price = e;
      //   if (tmpObj.num) {
      //     tmpObj.zh_price = floatMultiply(
      //       floatMultiply(Number(tmpObj.selling_price), 0.68),
      //       tmpObj.num
      //     );
      //   } else {
      //     tmpObj.zh_price = 0;
      //   }
      // } else {
      //   tmpObj.selling_price = "";
      //   tmpObj.zh_price = 0;
      // }
      // this.$set(this.TableDataNG, index, tmpObj);
      // this.multipleSelection = multipleSelection.map((e) => {
      //   if (e.id == tmpObj.id) return tmpObj;
      //   return e;
      // });
      // this.TableDataSelectSummary();
    },
    // 未归还转内购
    async onNGModel() {
      let { detail } = this;
      let obj = {
        allocation_number: detail.allocation_number,
      };
      let res = await postAdminOmsGetsAllocation_ipurchase(obj);
      let list = res.data;
      list = list.map((e) => {
        e.ngnum = e.num;
        e.num = 1;
        e.selling_price = "";
        e.zh_price = "";
        return e;
      });
      this.TableDataNG = list;
      this.dialogVisibleZNG = true;
    },
    // 归还列表
    async postAdminOmsgetWarehousereturn(data) {
      this.form = data;
      let form = JSON.parse(JSON.stringify(this.form));
      if (form.str_time) {
        form.str_time = `${data.str_time[0]}`;
        form.end_time = `${data.str_time[1]}`;
      } else {
        form.str_time = "";
        form.end_time = "";
      }
      let res = await postAdminOmsgetWarehousereturn(form);
      this.tableData = res.data;
    },
    // 关闭
    async postAdminOmssetAllocationtcclose() {
      let { detail } = this;
      let obj = {
        allocation_number: detail.allocation_number,
      };
      this.$confirm("确定关闭借出计划?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          await postAdminOmssetAllocationtcclose(obj);
          this.postAdminOmsgetAllocationtdetail(obj);
        })
        .catch(() => { });
    },
    async postAdminOmsgetWarehouseaddress() {
      let res = await postAdminOmsgetWarehouseaddress();
      let data = res.data;
      this.formGh.wp_user = data.part_a_receive;
      this.formGh.wp_phone = data.part_a_receive_tel;
      this.formGh.wp_address = data.part_a_place;
    },
    async onSubmit() {
      this.loading = true;
      let { multipleSelection, formGh, detail } = this;
      let arr = [];
      let is = multipleSelection.some((e) => {
        return (
          Number(e.sj_jc_num) - Number(e.sj_gh_num) - Number(e.num) < 0 ||
          !e.num
        );
      });
      if (is) {
        this.loading = false;
        this.$message.warning("归还数量不能大于实际数量且不能等于0");
      } else {
        for (let index = 0; index < multipleSelection.length; index++) {
          let obj = {
            id: multipleSelection[index].id,
            sku_code: multipleSelection[index].sku_code,
            num: multipleSelection[index].num,
          };
          arr.push(obj);
        }
        formGh.arrlist = arr;
        formGh.remark = formGh.remark.replace(/\r|\n/gi, "");
        formGh.reason = formGh.reason.replace(/\r|\n/gi, "");
        try {
          let res = await postAdminOmsSetAllocation(formGh);
          this.$message.success("提交成功");
          this.multipleSelection = [];
          let formGhL = {
            groups: 3,
            transport_type: "",
            allocation_number: "",
            logistics_company_code: "",
            remark: "",
            reason: "归还所借商品",
            ourier_number: "",
          };
          let formGhobj = { ...this.formGh, ...formGhL };
          this.formGh = formGhobj;
          this.multipleSelection = [];
          let data = {
            allocation_number: detail.allocation_number,
          };
          this.postAdminOmsgetAllocationtdetail(data);
          this.postAdminOmsgetWarehousereturn(this.form);
          this.dialogVisible = false;
          this.loading = false;
        } catch (error) {
          this.loading = false;
        }
      }
    },
    handleChange(val) {
      this.formGh.transport_type = this.Courier.find(
        (item) => item.logistics_company_code == val
      ).logistics_company_name;
    },
    onChecked(val, row) {
      let { list } = this;
      let multipleSelection = list.filter((e) => e.checked);
      this.multipleSelection = JSON.parse(JSON.stringify(multipleSelection));
    },
    async postAdminOmsgetlogisticsCompanyCode() {
      let res = await postAdminOmsgetlogisticsCompanyCode();
      this.Courier = res.data;
    },
    async postAdminOmsgetAllocationtdetail(data) {
      let res = await postAdminOmsgetAllocationtdetail(data);
      let list = res.data.list;
      list = list.map((e) => {
        e.num = "";
        e.checked = false;
        return e;
      });
      this.list = list;
      this.detail = res.data.detail;
    },
    // 转赠送列表
    async postAdminOmsGetWarehouseGive(data) {
      this.form = data;
      let form = JSON.parse(JSON.stringify(this.form));
      if (form.str_time) {
        form.str_time = `${data.str_time[0]}`;
        form.end_time = `${data.str_time[1]}`;
      } else {
        form.str_time = "";
        form.end_time = "";
      }
      let res = await postAdminOmsGetWarehouseGive(form);
      this.tableData = res.data;
    },
    onSearch() {
      let { form, radio } = this;
      if (radio == "转内购") {
        this.postAdminOmsGetWarehouseTransfer(form);
      } else if (radio == "转赠送") {
        this.postAdminOmsGetWarehouseGive(this.form)
      } else {
        this.postAdminOmsgetWarehousereturn(this.form);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.fileimg {
  width: 178px;
  height: 178px;
  position: relative;
  border: 1px dashed #d9d9d9;

  .fileimg-image {
    width: 178px;
    height: 178px;
  }

  .fileimg-operation {
    position: absolute;
    top: 0;
    left: 0;
    width: 178px;
    height: 178px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba($color: #000000, $alpha: 0.2);
    color: #fff;

    >div:nth-child(1) {
      margin-right: 10px;
    }

    font-size: 24px;
  }
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}

.zk {
  display: flex;
  align-items: center;
  margin-bottom: 10px;

  >div {
    width: 100px;
  }
}

.info {
  display: flex;
  margin-top: 15px;

  >div {
    margin-right: 20px;

    > :nth-child(1) {
      font-size: 12px;
      margin-bottom: 10px;
    }

    >div:nth-child(2) {
      display: flex;
      align-items: center;
    }
  }
}

.Transfers {
  background: #fff;
  font-size: 14px;
  padding: 20px 0;

  .Transfers-type {

    // display: flex;
    // align-items: center;
    >div {
      padding: 10px 20px;
      margin: 0 20px 10px;
      background: #efefef;
      border-radius: 8px;

      >div:nth-child(1) {
        font-weight: 600;
      }

      >div:nth-child(2) {
        color: red;
      }
    }

    >div:nth-child(2) {
      padding: 10px 20px;
      margin: 0 20px 10px;
      background: #efefef;
      border-radius: 8px;

      >div:nth-child(1) {
        font-weight: 400;
      }

      >div:nth-child(2) {
        color: #333;
        margin-left: 10px;

        >div {
          >span {
            margin-left: 10px;
            color: #2c70d6;
          }
        }
      }
    }
  }
}

.goodsInfo {
  display: flex;

  >.el-image {
    width: 80px;
    height: 80px;
  }

  >div:nth-child(2) {
    width: 280px;
    margin-left: 10px;

    >div:nth-child(1) {
      font-weight: 600;
      font-size: 14px;
    }

    >div:nth-child(2) {
      font-size: 14px;
    }

    >div:nth-child(3) {
      color: #999;
      font-size: 14px;
    }
  }
}

.content {
  .content-one {
    display: flex;
    align-items: center;

    >div {
      margin-right: 10px;
    }
  }

  .content-two {
    display: flex;
    margin-top: 10px;

    >div {
      margin-right: 10px;

      >div {
        display: flex;
        margin-bottom: 10px;
      }
    }
  }
}

.myform {
  display: flex;
  justify-content: space-between;

  >div {
    display: flex;
  }

  &-item {
    margin-right: 10px;
  }
}

.Statisticsadmin {
  font-size: 12px;

  .Statisticsadmin-one {
    padding: 25px;
    background: #fff;

    >div:nth-child(1) {
      display: flex;

      >div:nth-child(1) {
        font-weight: 600;
        font-size: 18px;
      }

      >div:nth-child(2) {
        color: #fff;
        border-radius: 4px;
        height: 24px;
        line-height: 24px;
        padding: 0 10px;
        margin: 0 10px;
      }

      >div:nth-child(3) {
        border-radius: 4px;
        height: 22px;
        line-height: 22px;
        border-style: solid;
        border-width: 1px;
        padding: 0 10px;
      }
    }

    >div:nth-child(2) {
      margin-top: 15px;
      font-size: 14px;
      display: flex;

      >div:not(:nth-last-child(1)) {
        border-right: 1px solid #ddd;
      }

      >div:not(:nth-child(1)) {
        padding: 0 20px;
      }

      >div:nth-child(1) {
        padding-right: 20px;
      }
    }

    >div:nth-child(3) {
      margin-top: 15px;
      font-size: 12px;
      display: flex;
      align-items: center;

      >div:not(:nth-last-child(1)) {
        border-right: 1px solid #ddd;
      }

      >div:not(:nth-child(1)) {
        padding: 0 20px;
      }

      >div:nth-child(1) {
        padding-right: 20px;
        display: flex;
        align-items: center;

        >div:nth-child(1) {
          border: 1px solid #2c70d6;
          border-radius: 50%;
          width: 20px;
          height: 20px;
          color: #2c70d6;
          font-size: 12px;
          text-align: center;
          line-height: 20px;
          margin-right: 10px;
        }
      }

      >div:nth-child(2) {
        color: #999;
      }

      >div:nth-child(3) {
        display: flex;
        align-items: center;
        color: #999;

        >div:nth-child(1) {
          border: 1px solid #2c70d6;
          border-radius: 50%;
          width: 20px;
          height: 20px;
          color: #2c70d6;
          font-size: 12px;
          text-align: center;
          line-height: 20px;
          margin-right: 10px;
        }
      }
    }
  }

  .Statisticsadmin-two {
    margin-top: 10px;
    padding: 25px;
    background: #fff;

    .Statisticsadmin-two-title {
      font-size: 14px;
      font-weight: 600;
    }
  }
}
</style>